<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
     <div>
       <el-form-item label="查询时间">
         <el-date-picker
           v-model="queryParams.dealDate"
           type="date"
           value-format="yyyy-MM-dd"
           clearable
           placeholder="选择日期时间">
         </el-date-picker>
         <span>至</span>
         <el-date-picker
           value-format="yyyy-MM-dd"
           clearable
           v-model="queryParams.dealDate1"
           type="date"
           placeholder="选择日期时间">
         </el-date-picker>
       </el-form-item>
     </div>
      <el-form-item>
        <el-button type="warning" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="收入明细" name="first">
        <p><span style="font-size: 25px">金额统计：</span><b>{{dealPerDay.totalSum}}</b>元</p>
        <p>
          押金(总计)：<b>{{dealPerDay.depositSum}}</b>&emsp;&emsp;
          租金(总计)：<b>{{dealPerDay.rentSum}}</b>&emsp;&emsp;
          电费(总计)：<b>{{dealPerDay.electricityFeeSum}}</b>&emsp;&emsp;
          水费(总计)：<b>{{dealPerDay.waterFeeSum}}</b>&emsp;&emsp;
          宽带费(总计)：<b>{{dealPerDay.netFeeSum}}</b>&emsp;&emsp;
          燃气费(总计)：<b>{{dealPerDay.gasFeeSum}}</b>&emsp;&emsp;
        </p>
        <p>
          有线电视费(总计)：<b>{{dealPerDay.cableFeeSum}}</b>&emsp;&emsp;
          其他(总计)：<b>{{dealPerDay.otherFeeSum}}</b>
        </p>
        <el-table v-loading="loading" :data="dayList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column label="交易时间" align="center" prop="dealDate" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.dealDate, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="总计（元）" align="center" prop="total" />
          <el-table-column label="押金（元）" align="center" prop="deposit" />
          <el-table-column label="租金（元）" align="center" prop="rent" />
          <el-table-column label="电费（元）" align="center" prop="electricityFee" />
          <el-table-column label="水费（元）" align="center" prop="waterFee" />
          <el-table-column label="宽带费（元）" align="center" prop="netFee" />
          <el-table-column label="燃气费（元）" align="center" prop="gasFee" />
          <el-table-column label="有线电视费（元）" align="center" prop="cableFee" />
          <el-table-column label="其他（元）" align="center" prop="otherFee" />
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                @click="showDealPerDay(scope.row)"
              ><span style="color: orange">查看</span></el-button>
            </template>
          </el-table-column>
        </el-table>

        <el-dialog
          title="提示"
          :visible.sync="dialogVisible"
          width="80%">
          <div>
            <p>交易日期：{{receiptForm.dealDate}}  收入金额统计：{{receiptForm.sumTotal}}</p>
            <el-table v-loading="loading" :data="tableData" @selection-change="handleSelectionChange">
              <el-table-column type="selection" width="55" align="center" />
              <el-table-column label="序号" align="center" prop="id" />
              <el-table-column label="交易时间" align="center" prop="dealDate" width="180">
                <template slot-scope="scope">
                  <span>{{ parseTime(scope.row.dealDate, '{y}-{m}-{d}') }}</span>
                </template>
              </el-table-column>

              <el-table-column label="房源名称" align="center" prop="roomName" />
              <el-table-column label="租客姓名" align="center" prop="tenantName" />
              <el-table-column label="租客电话" align="center" prop="tenantId">
                <template slot-scope="scope">
                  <span v-for="item in receiptForm.mtenantList" v-if="scope.row.tenantId==item.id">{{item.tenantPhone}}</span>
                </template>
              </el-table-column>
              <el-table-column label="费用类型" align="center" prop="bill_type" />
              <el-table-column label="收支状态" align="center" prop="skStatus" />
              <el-table-column label="金额" align="center" prop="realPaymentAmount" />
              <el-table-column label="支付方式" align="center" prop="payMethod" />
            </el-table>

            <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="currentPage4"
              :page-sizes="[10, 20, 30, 40]"
              :page-size="receiptForm.pageSize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="this.receiptForm.total">
            </el-pagination>
            <el-button type="warning" @click="beforDay">前一天</el-button>
            <el-button type="warning" @click="afterDay">后一天</el-button>
          </div>
          <span slot="footer" class="dialog-footer">
    <el-button type="primary" @click="queding">确 定</el-button>
  </span>
        </el-dialog>

      </el-tab-pane>


      <el-tab-pane label="支出明细" name="second">
        <p><span style="font-size: 25px">金额统计：</span><b>{{dealPerDay.totalSum}}</b>元</p>
        <p>
          押金(总计)：<b>{{dealPerDay.depositSum}}</b>&emsp;&emsp;
          租金(总计)：<b>{{dealPerDay.rentSum}}</b>&emsp;&emsp;
          电费(总计)：<b>{{dealPerDay.electricityFeeSum}}</b>&emsp;&emsp;
          水费(总计)：<b>{{dealPerDay.waterFeeSum}}</b>&emsp;&emsp;
          宽带费(总计)：<b>{{dealPerDay.netFeeSum}}</b>&emsp;&emsp;
          燃气费(总计)：<b>{{dealPerDay.gasFeeSum}}</b>&emsp;&emsp;
        </p>
        <p>
          有线电视费(总计)：<b>{{dealPerDay.cableFeeSum}}</b>&emsp;&emsp;
          其他(总计)：<b>{{dealPerDay.otherFeeSum}}</b>
        </p>
        <el-table v-loading="loading" :data="dayList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column label="交易时间" align="center" prop="dealDate" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.dealDate, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="总计（元）" align="center" prop="total" />
          <el-table-column label="押金（元）" align="center" prop="deposit" />
          <el-table-column label="租金（元）" align="center" prop="rent" />
          <el-table-column label="电费（元）" align="center" prop="electricityFee" />
          <el-table-column label="水费（元）" align="center" prop="waterFee" />
          <el-table-column label="宽带费（元）" align="center" prop="netFee" />
          <el-table-column label="燃气费（元）" align="center" prop="gasFee" />
          <el-table-column label="有线电视费（元）" align="center" prop="cableFee" />
          <el-table-column label="其他（元）" align="center" prop="otherFee" />
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                @click="showZhiChu(scope.row)"
              ><span style="color: orange">查看</span></el-button>
            </template>
          </el-table-column>
        </el-table>

        <el-dialog title="" :visible.sync="dialogTableVisible">
          <el-table v-loading="loading" :data="tableData" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="序号" align="center" prop="id" />
            <el-table-column label="交易时间" align="center" prop="paidTime" width="180">
              <!--<template slot-scope="scope">
                <span>{{ parseTime(scope.row.dealDate, '{y}-{m}-{d}') }}</span>
              </template>-->
            </el-table-column>

            <el-table-column label="房源名称" align="center" prop="premiseName" />
            <el-table-column label="租客姓名" align="center" prop="tenantName" />
            <el-table-column label="租客电话" align="center" prop="tenantId">
<!--              <template slot-scope="scope">-->
<!--                <span v-for="item in receiptForm.mtenantList" v-if="scope.row.tenantId==item.id">{{item.tenantPhone}}</span>-->
<!--              </template>-->
            </el-table-column>
            <el-table-column label="费用类型" align="center" prop="bill_type" />
            <el-table-column label="收支状态" align="center" prop="paytype" />
            <el-table-column label="金额" align="center" prop="paymentAmount" />
            <el-table-column label="支付方式" align="center" prop="payMethod" />
          </el-table>
          <el-button type="warning" @click="beforDay">前一天</el-button>
          <el-button type="warning" @click="afterDay">后一天</el-button>
          <el-button type="primary" @click="zhichuQueding">确 定</el-button>
        </el-dialog>

        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage4"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="receiptForm.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="this.receiptForm.total">
        </el-pagination>

      </el-tab-pane>
     </el-tabs>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import { listDay, getDay, delDay, addDay, updateDay,moneyStatistics,showInfo,zhiChuInfo } from "@/api/finance/day";

export default {
  name: "Day",
  components: {
  },
  data() {
    return {
      currentPage4:1,
      tableData:[],
      dealDate:null,
      dialogTableVisible:false,
      skStatus:null,
      dialogVisible: false,
      rq:null,
      receiptForm:{
        pageNum:1,
        pageSize: 10,
        total:0,
      },
      //收款计划表集合
      receiptPlanList:[],
      //租客集合
      mTenantList:[],
      dealPerDay:{},
      activeName: 'first',
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      dayList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        businessId: null,
        businessName: null,
        onlineFlg: null,
        dealDate: null,
        operationType: null,
        total: null,
        deposit: null,
        rent: null,
        electricityFee: null,
        waterFee: null,
        netFee: null,
        gasFee: null,
        cableFee: null,
        czFee: null,
        otherFee: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        delFlg: null,
        createUserid: null,
        updateUserid: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ],
        updateTime: [
          { required: true, message: "更新时间不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
    this.getMoneyStatistics();
  },
  methods: {
    zhichuQueding() {
        this.rq=null,
        this.dialogTableVisible=false;
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.receiptForm.pageSize=val;
      this.getShow();
      this.getZhiChu();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.receiptForm.pageNum=val;
      this.getShow();
      this.getZhiChu();
    },
    queding() {
      this.rq=null;
      this.dialogVisible=false
    },
    afterDay() {
      this.rq+=1;
     this.getShow();
     this.getZhiChu();
    },
    beforDay() {
      this.rq-=1;
    this.getShow();
    this.getZhiChu();
    },
    //统计
    getMoneyStatistics() {
      this.loading = true;
      if (this.activeName == "second") {
        this.queryParams.operationType=2;
      }else {
        this.queryParams.operationType=1;
      }
      moneyStatistics(this.queryParams).then(response => {
        console.log(response)
        this.dealPerDay=response.data
      });
    },
    getZhiChu() {
      zhiChuInfo({dealDate:this.dealDate,rq:this.rq,pageNum:this.receiptForm.pageNum,pageSize:this.receiptForm.pageSize}).then(res=>{
        console.log("show==========",res);
        this.receiptForm=res.data
        this.tableData=res.data.pg.list
        this.receiptForm.total=res.data.pg.total
      })
    },
    showZhiChu(row) {
      this.dialogTableVisible = true
      this.dealDate=row.dealDate
      this.getZhiChu();
    },
    getShow() {
      showInfo({dealDate:this.dealDate,rq:this.rq,pageNum:this.receiptForm.pageNum,pageSize:this.receiptForm.pageSize}).then(res=>{
        console.log("show==========",res);
        this.receiptForm=res.data
        this.tableData=res.data.pg.list
        this.receiptForm.total=res.data.pg.total
      });
    },
    //查看
    showDealPerDay(row) {
      this.dialogVisible = true
      this.dealDate=row.dealDate
      this.getShow();
    },
    //tabs标签
    handleClick(tab, event) {
      this.dialogVisible=false;
      console.log(tab, event);
      this.activeName=tab.name
      this.getList();
      this.getMoneyStatistics();
    },
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      if (this.activeName == "second") {
        this.queryParams.operationType=2;
      }else {
        this.queryParams.operationType=1;
      }
      listDay(this.queryParams).then(response => {
        this.dayList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        businessId: null,
        businessName: null,
        onlineFlg: null,
        dealDate: null,
        operationType: null,
        total: null,
        deposit: null,
        rent: null,
        electricityFee: null,
        waterFee: null,
        netFee: null,
        gasFee: null,
        cableFee: null,
        czFee: null,
        otherFee: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        delFlg: null,
        createUserid: null,
        createTime: null,
        updateUserid: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加【请填写功能名称】";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getDay(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改【请填写功能名称】";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateDay(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDay(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除【请填写功能名称】编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delDay(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('finance/day/export', {
        ...this.queryParams
      }, `finance_day.xlsx`)
    }
  }
};
</script>
